﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Linq;
using System.Windows.Forms;
using DevExpress.XtraEditors;
using DevExpress.Utils;
using POS.Framework;
using Model.Bill;
using DevExpress.Xpo;
using BLL;
using DevExpress.Data.Filtering;
using BLL.Enums;
using DevExpress.Xpo.DB;

namespace POS.ModForm.Report
{
    public partial class frmPayment : DevExpress.XtraEditors.XtraForm
    {
        public frmPayment()
        {
            InitializeComponent();
        }

        private void frmPayment_Load(object sender, EventArgs e)
        {
            using (WaitDialogForm wdf = new WaitDialogForm(MsgBox.WaitLoading))
            {
                this.gridView2.CustomDrawRowIndicator += new DevExpress.XtraGrid.Views.Grid.RowIndicatorCustomDrawEventHandler(SpecialGridView.DrawRowIndicator);
                this.repositoryItemLookUpEditOrderType.DataSource = EnumManage.GetDictionaryEntry(typeof(OrderType));
                this.repositoryItemLookUpEditPaymentStatus.DataSource = EnumManage.GetDictionaryEntry(typeof(PaymentStatus));
                SetButtonClickEvent();
                SearchData();
            }
        }
        void SetButtonClickEvent()
        {
            this.listButtonUC.IsHide(new List<string> { "btnNew" });
            this.listButtonUC.Query.Click += new EventHandler(Query_Click);
        }
        void Query_Click(object sender, EventArgs e)
        {
            using (WaitDialogForm wdf = new WaitDialogForm(MsgBox.WaitLoading))
            {
                SearchData();
                wdf.Close();
            }
        }
        void SearchData()
        {
            GroupOperator goFilter = new GroupOperator();
            if (!string.IsNullOrEmpty(this._SellDateStart.Text.Trim()))
                goFilter.Operands.Add(CriteriaOperator.Parse("OrderID.SellDate>=?", this._SellDateStart.Text.Trim()));
            if (!string.IsNullOrEmpty(this._SellDateEnd.Text.Trim()))
                goFilter.Operands.Add(CriteriaOperator.Parse("OrderID.SellDate<?", this._SellDateEnd.Text.Trim() + " 23:58:58"));
            if (!string.IsNullOrEmpty(this._PayDateStart.Text.Trim()))
                goFilter.Operands.Add(CriteriaOperator.Parse("PayDate>=?", this._PayDateStart.Text.Trim()));
            if (!string.IsNullOrEmpty(this._PayDateEnd.Text.Trim()))
                goFilter.Operands.Add(CriteriaOperator.Parse("PayDate<?", this._PayDateEnd.Text.Trim() + " 23:58:58"));
            if (!string.IsNullOrEmpty(this._BillCode.Text.Trim()))
                goFilter.Operands.Add(CriteriaOperator.Parse(string.Format("OrderID.BillCode like '{0}'", this._BillCode.Text.Trim())));
            XPCollection<TB_OrderPay> sd = new DevExpress.Xpo.XPCollection<TB_OrderPay>(DatabaseSchema.Session, goFilter, new SortProperty("CreateDT", SortingDirection.Descending));
            this._gcStockDetail.DataSource = sd;
            SpecialGridView.SetGridViewIndicatorWidth(sd.Count, this.gridView2);
        }
    }
}